package yf.mall.service.impl;

import org.apache.commons.collections.MultiMap;
import org.apache.commons.collections.map.MultiValueMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import yf.mall.dao.MallSkuDao;
import yf.mall.entity.MallSkuEntity;
import yf.mall.service.MallSkuService;
import com.yf.service.impl.BaseServiceImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * SKU详情Service实现类
 *
 *
 *
 * @date Thu Aug 08 17:38:32 CST 2019
 */
@Service
public class MallSkuServiceImpl extends BaseServiceImpl<MallSkuEntity> implements MallSkuService {

    private MallSkuDao mallSkuDao;


    @Autowired
    public void setDao(MallSkuDao mallSkuDao) {
        this.mallSkuDao = mallSkuDao;
        super.setBaseDao(mallSkuDao);
    }


    /**内部方法**/


    /**
     * 外部方法实现
     **/

    @Override
    public Map findByGoodsId(Long goodsId) {
        List<MallSkuEntity> items = mallSkuDao.queryListByGoodsId(goodsId);
        if (items.isEmpty()) return null;
        String[] themes = items.get(0).getTheme().split("-");
        MultiMap themeMap = new MultiValueMap();
        Map skuMap = new HashMap();
        for (MallSkuEntity item : items) {
            if(item.getDisable()){
                continue;
            }
            skuMap.put(item.getName(),item);
            for (int i = 0; i < themes.length; i++) {
                themeMap.put(themes[i],item.getName().split("-")[i]);
            }
        }
        Map res = new HashMap();
        res.put("themeMap",themeMap);
        res.put("skuMap",skuMap);
        return res;
    }


}
